<%@ page contentType="text/html;charset=UTF-8" language="java" %> 

<%@ page import="
	java.util.*
	, javax.jdo.*
	, com.google.appengine.api.datastore.*
	, com.airbach.chart.*
	, com.airbach.chart.kpop.daum.*
	, com.airbach.chart.kpop.melon.*
	, com.airbach.chart.kpop.bugs.*" %>

<%
	request.setCharacterEncoding("utf-8");

	String account = request.getParameter("account");
	System.out.println("account : " + account);
	
	String version_code = request.getParameter("version_code");
	System.out.println("version_code : " + version_code);

	String chart_id = request.getParameter("chart_id");
	System.out.println("chart_id : " + chart_id);
	
	String dtype = request.getParameter("dtype");
	System.out.println("dtype : " + dtype);

	if(account == null || version_code == null || chart_id == null || dtype == null) {
		response.sendRedirect("./error.html");
	} else {
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		ChartData chartdata = null;
		Key key = null;
		
		try {
			// KOREA Daum Idol Top 100 chart
			if(C.CHART_ID_KOREA_DAUM_IDOL_TOP100.equals(chart_id)) {
			    key = KeyFactory.createKey(ChartData.class.getSimpleName(), com.airbach.chart.kpop.daum.Idol.class.getName() + "." + dtype);
			}
			
			// KOREA Daum Kpop Top 100 chart
			else if(C.CHART_ID_KOREA_DAUM_KPOP_TOP100.equals(chart_id)) {
			    key = KeyFactory.createKey(ChartData.class.getSimpleName(), com.airbach.chart.kpop.daum.Kpop.class.getName() + "." + dtype);
			}
			
			// KOREA Melon RealTime Top 100 chart
			else if(C.CHART_ID_KOREA_MELON_LIVE_TOP100.equals(chart_id)) {
				key = KeyFactory.createKey(ChartData.class.getSimpleName(), com.airbach.chart.kpop.melon.Live.class.getName() + "." + dtype);
			}
			
			// KOREA Melon Daily Top 100 chart
			else if(C.CHART_ID_KOREA_MELON_DAILY_TOP100.equals(chart_id)) {
				key = KeyFactory.createKey(ChartData.class.getSimpleName(), com.airbach.chart.kpop.melon.Daily.class.getName() + "." + dtype);
			}
			
			// KOREA Bugs RealTime Top 50 chart
			else if(C.CHART_ID_KOREA_BUGS_LIVE_TOP100.equals(chart_id)) {
				key = KeyFactory.createKey(ChartData.class.getSimpleName(), com.airbach.chart.kpop.bugs.Live.class.getName() + "." + dtype);
			}
			
			// KOREA Bugs Daily Top 100 chart
			else if(C.CHART_ID_KOREA_BUGS_DAILY_TOP100.equals(chart_id)) {
				key = KeyFactory.createKey(ChartData.class.getSimpleName(), com.airbach.chart.kpop.bugs.Daily.class.getName() + "." + dtype);
			}
			
			//뭔가 제한된 정보를 제공하자.
			else {

			}
			chartdata = pm.getObjectById(ChartData.class, key);
	    	out.print(chartdata.getChart().getValue()); 
		} catch(Exception e) {
	    	//e.printStackTrace();
	    } finally {
	    	pm.close();
	    }
		

	}

%>